package com.syaccp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syaccp.model.TOrderCategory;
import com.syaccp.service.TOrderCategoryService;
import com.syaccp.mapper.TOrderCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author DX
* @description 针对表【t_order_category(素材分类表)】的数据库操作Service实现
* @createDate 2023-07-25 09:12:24
*/
@Service
public class TOrderCategoryServiceImpl extends ServiceImpl<TOrderCategoryMapper, TOrderCategory> implements TOrderCategoryService{
    @Autowired
    TOrderCategoryMapper tOrderCategoryMapper;

    @Override
    public List<TOrderCategory> queryFirstClassify() {
        LambdaQueryWrapper<TOrderCategory> queryWrapper = Wrappers.lambdaQuery(TOrderCategory.class);
        queryWrapper.eq(TOrderCategory::getParentId,0);
        return tOrderCategoryMapper.selectList(queryWrapper);
    }

    @Override
    public List<TOrderCategory> queryLastClassify(Integer id) {
        LambdaQueryWrapper<TOrderCategory> queryWrapper = Wrappers.lambdaQuery(TOrderCategory.class);
        queryWrapper.eq(ObjectUtils.isNotEmpty(id),TOrderCategory::getParentId,id);
        return tOrderCategoryMapper.selectList(queryWrapper);
    }


    @Override
    public List<TOrderCategory> queryOrderCategoryByParentId(Integer parentId) {
        LambdaQueryWrapper<TOrderCategory> lqw = Wrappers.lambdaQuery();
        lqw.eq(TOrderCategory::getParentId, parentId)
                .eq(TOrderCategory::getStatus, 0)
                .orderByAsc(TOrderCategory::getSort);
        return tOrderCategoryMapper.selectList(lqw);
    }

    @Override
    public List<TOrderCategory> queryTotalLevelOrderCategory() {
        return queryOrderCategoryByParentId(0).stream().peek(item -> {
            item.setGradeOrderCategory(queryOrderCategoryByParentId(item.getId()));
        }).collect(Collectors.toList());
    }
}




